package com.wwg.base.label;

public class LabelTest {

    public static void main(String[] args) {
        String strSearch = "This is the string in which you have to search for a substring.";

        String substring = "substring";

        boolean found = false;

        int max = strSearch.length() - substring.length();

        testlbl:

        for (int i = 0; i <= max; i++) {
            int length = substring.length();

            int j = i;

            int k = 0;

            while (length-- != 0) {
                if(strSearch.charAt(j++) != substring.charAt(k++)){
                    continue testlbl;

                }

            }

            found = true;

            break testlbl;

        }

        if (found) {
            System.out.println("发现子字符串。");

        }

        else {
            System.out.println("字符串中没有发现子字符串。");

        }

    }

/*————————————————
        版权声明：本文为CSDN博主「牛然」的原创文章，遵循CC 4.0 BY-SA版权协议，转载请附上原文出处链接及本声明。
        原文链接：https://blog.csdn.net/weixin_34233720/article/details/114351860*/

}
